package Main;

import LunaServer.core.LunaServer;
import LunaServer.gui.ServerManagerGUI;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class Main {
    // 数据库连接参数
    private static final String DB_URL = "jdbc:postgresql://127.0.0.1:1980/postgres";
    private static final String DB_USER = "postgres";
    private static final String DB_PASSWORD = "lunamoon";

    public static void main(String[] args) {
        // 检查是否需要启动GUI
        boolean useGUI = false;
        for (String arg : args) {
            if ("-gui".equals(arg)) {
                useGUI = true;
                break;
            }
        }

        if (useGUI) {
            // 启动GUI模式
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        // 设置系统外观
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    new ServerManagerGUI().setVisible(true);
                }
            });
        } else {
            // 启动命令行模式
            LunaServer server = new LunaServer();
            server.setDatabaseConfig(DB_URL, DB_USER, DB_PASSWORD);

            try {
                server.startServer(6003);
            } catch (Exception e) {
                System.err.println("Failed to start server: " + e.getMessage());
                e.printStackTrace();
            }
        }
    }
}